#include <iostream>
#include <vector>
#include <algorithm>

class Solution {
public:
    static int triangleNumber(std::vector<int>& nums) {
        std::sort(nums.begin(), nums.end());//对数组进行排序
        int cnt = 0;
        int max = nums.size()-1;//最大下标
        while(max >= 2)
        {
            //逻辑：
            //1、假如nums[left]+nums[right]>nums[max],则cnt+=right-left&&right--
            //2、反之则left++，直到left==right
            int left = 0;
            int right = max-1;
            while(left<=right)
            {
                if(nums[left]+nums[right]>nums[max])
                {
                    cnt += right-left;
                    right--;
                }
                else left++;
            }
            max--;
        }
        return cnt;
    }
};

int main()
{
    // std::vector<int> nums = {2,2,3,4};
    std::vector<int> nums = {4,2,3,4};
    // std::cout << (Solution::triangleNumber(nums)==3) << std::endl;
    std::cout << (Solution::triangleNumber(nums)==4) << std::endl;
    return 0;
}